﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for WebServiceDRM
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebServiceDRM : System.Web.Services.WebService {

    static ClassExecute.ClassExecute dt;
    static string str = webapp4U.Configuration.CurrentConnectionString;
    static string error = "";
    public WebServiceDRM () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [WebMethod]
    public string[] GetMatHangInfo(string prefixText, int count)
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getFilterListMatHang", CommandType.StoredProcedure,
                new SqlParameter("@filter",prefixText));

            List<string> items = new List<string>(count);
            for (int i = 0; i < db.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(db.Rows[i]["MaTenHang"].ToString(), db.Rows[i]["MaTenHang"].ToString());
                items.Add(strName);
            }

            return items.ToArray();
        }
        catch
        {
            return new string[] { "Không có dữ liệu" };
        }
    }
    [WebMethod]
    public string[] GetNPPInfo(string prefixText, int count)
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getFilterListNPP", CommandType.StoredProcedure,
                new SqlParameter("@filter", prefixText));

            List<string> items = new List<string>(count);
            for (int i = 0; i < db.Rows.Count; i++)
            {
                string strName = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(db.Rows[i]["MaTenNPP"].ToString(), db.Rows[i]["MaTenNPP"].ToString());
                items.Add(strName);
            }

            return items.ToArray();
        }
        catch
        {
            return new string[] { "Không có dữ liệu" };
        }
    }
    
}
